package br.com.estevam.sisfin.entities;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.tapestry5.beaneditor.NonVisual;
import org.apache.tapestry5.beaneditor.Validate;
import org.apache.tapestry5.beaneditor.Width;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Index;

@Entity
@Table(name = "TblAgencia")
public class Agencia extends AbstractEntity {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@NonVisual
	private long id;

	@Column(length = 6, nullable = false, unique = true)
	@Validate("maxlength=6")
	private String codAgencia;

	@Column(length = 50, nullable = false)
	@Validate("maxlength=50")
	@Width(30)
	private String descricao;

	@ManyToOne
	@JoinColumn(name="codBanco", nullable = false)
	@ForeignKey(name = "FK_agencia_banco")
	@Index(name = "ix_codBanco")
	private Banco banco;

	@Inject
	public Agencia() { }

	public Agencia(String codAgencia, String descricao, Banco banco) {
		super();
		this.codAgencia = codAgencia;
		this.descricao = descricao;
		this.banco = banco;
	}
	
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getCodAgencia() {
		return codAgencia;
	}

	public void setCodAgencia(String codAgencia) {
		this.codAgencia = codAgencia;
	}

	public String getDescricao() {
		return descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	public Banco getBanco() {
		return banco;
	}

	public void setBanco(Banco banco) {
		this.banco = banco;
	}

	@Transient
	public String getDescBanco(){
		return banco.getDescricao();
	}
	
	public String toString(){
		return "" + id + "---" + getUserId();
	}

}
